package br.univas.vperiod.jowey.dao;

import java.util.ArrayList;

import javax.persistence.TypedQuery;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.univas.vperiod.jowey.entities.Player;
import br.univas.vperiod.jowey.entities.PlayerJob;

@Repository
@Transactional
public class PlayerDAO implements IPlayerDAO<Player> {
	
	@Autowired
	private SessionFactory factory;

	public void save(Player player) {
		factory.getCurrentSession().save(player);
	}

	@SuppressWarnings("unchecked")
	public ArrayList<Player> findAll() {
		return (ArrayList<Player>) factory.getCurrentSession().createCriteria(Player.class).list();
	}

	public Player findByName(String name) {
		return (Player) factory.getCurrentSession().createCriteria(Player.class).uniqueResult();
	}
	
	@SuppressWarnings("unchecked")
	public ArrayList<PlayerJob> getPlayersInProjects(){
		return (ArrayList<PlayerJob>) factory.getCurrentSession()
				.createCriteria(PlayerJob.class)
				.add(Restrictions.eq("status", "OPEN").ignoreCase()).list();
	}
	

	public Player findById(long id) {
		// TODO Auto-generated method stub
		return null;
	}
}
